package com.ruge.core.exception;

/**
 * @author ruge.wu
 * @since 2021/12/21 14:14
 */
public class BaseBusinessException extends RuntimeException{
    private IError error;
    private String extMessage;
    public BaseBusinessException(IError error) {
        super(error.getErrorCode() + ", " + error.getErrorMessage());
        this.extMessage = null;
        this.error = error;
    }
    public BaseBusinessException(IError error, String extMessage) {
        super(error.getErrorCode() + ", " + error.getErrorMessage() + ", " + extMessage);
        this.extMessage = extMessage;
        this.error = error;
    }

    public BaseBusinessException(final String errorCode, final String errorMessage, String extMessage) {
        super(errorCode + ", " + errorMessage + ", " + extMessage);
        this.extMessage = extMessage;
        this.error = new IError() {
            @Override
            public String getNamespace() {
                return null;
            }

            @Override
            public String getErrorCode() {
                return errorCode;
            }

            @Override
            public String getErrorMessage() {
                return errorMessage;
            }
        };
    }

    public BaseBusinessException(final String namespace, final String errorCode, final String errorMessage, String extMessage) {
        super(namespace + "." + errorCode + ", " + errorMessage + ", " + extMessage);
        this.extMessage = extMessage;
        this.error = new IError() {
            @Override
            public String getNamespace() {
                return namespace;
            }

            @Override
            public String getErrorCode() {
                return errorCode;
            }

            @Override
            public String getErrorMessage() {
                return errorMessage;
            }
        };
    }

    public IError getError() {
        return this.error;
    }

    public void setError(IError error) {
        this.error = error;
    }

    public String getExtMessage() {
        return this.extMessage;
    }

    public void setExtMessage(String extMessage) {
        this.extMessage = extMessage;
    }

    @Override
    public String toString() {
        return "ErrorCode : " + this.error.getErrorCode() + ", ErrorMessage : " + this.error.getErrorMessage() + ", ExtMessage : " + this.extMessage;
    }
}
